package base.think.c11chiyou;

import java.util.ArrayList;
import java.util.Iterator;

class Apple {
	private static long counter;
	private final long id=counter++;
	public long getId(){
		return id;
	}
}
class GrannySmith extends Apple{}
class Gala extends Apple{}
class Fuji extends Apple{}
class Braeburn extends Apple{}


public class GenericsAndUpcasting {
	
	public static void main(String[] args) {
		ArrayList<Apple> apples=new ArrayList<Apple>();
		apples.add(new GrannySmith());
		apples.add(new Gala());
		apples.add(new Fuji());
		apples.add(new Braeburn());
		for(Apple a:apples){
			System.out.println(a);
		}
		Iterator<Apple> iterator=apples.iterator();
		while(iterator.hasNext()){
			Apple apple=iterator.next();
			System.out.println(apple);
		}
	}
	
}